package com.crazy.crazybusinessservice.controller;

import com.crazy.crazybusinessservice.service.DayInitializationService;
import com.crazy.crazycommon.common.BaseResponse;
import com.crazy.crazycommon.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.crazy.crazycommon.common.ErrorCode.OPERATION_ERROR;

@RestController
@RequestMapping("/liquidation")
@Slf4j
public class LiquidationController {
    @Resource
    private DayInitializationService dayInitializationService;

    @GetMapping("/dayinit")
    public BaseResponse DayInit() {
        boolean isworkingday = dayInitializationService.isWorkingDay();
        if (isworkingday) {
            dayInitializationService.updateAllNetworth();
            dayInitializationService.insertDayInitialization();
            return ResultUtils.success("OK");
        }
        else {
            return ResultUtils.error(OPERATION_ERROR);
        }

    }

}
